<template>
   <van-nav-bar
  title="订单"
  left-text="返回"
  left-arrow
  @click-left="()=>{$router.back('/')}"
/>
<van-address-list
  v-model="chosenAddressId"
  :list="list"
  :disabled-list="disabledList"
  default-tag-text="默认"
  @add="onAdd"
  @edit="onEdit"
  :show-add-button="false"
/>
<van-card
v-for="item in orderdata"
  :num="item.number"
  :price="item.goods.goods_price"
  :title="item.goods.goods_name"
  :thumb="item.goods.goods_big_logo"
/>
<van-submit-bar :price="payData.totalPrice*100" button-text="支付" @submit="onSubmit" />
</template>

<script setup>
const list = [
      {
        id: '1',
        name: '张三',
        tel: '13000000000',
        address: '浙江省杭州市西湖区文三路 138 号东方通信大厦 7 楼 501 室',
        isDefault: true,
      },]

import {ref} from 'vue'
import {orderDetailApi} from '@/api/api'
import { useRoute } from 'vue-router';
let route=new useRoute()
import { useCounterStore } from "@/store/cart";
// 可以在组件中的任意位置访问 `store` 变量 ✨
const store = useCounterStore();

let orderdata=ref([])
orderDetailApi(route.params.orderId).then((res)=>{
    console.log('订单列表数据',res)
    orderdata.value=res.data.data
    let orderAllData=store.carts||[]
    let goodsIds=res.data.data.goods.map(item=>+item.goods_id)
    orderAllData=orderAllData.filter((item)=>{
        return goodsIds.includes(+item.goods.goods_id)
    })
    orderdata.value=orderAllData

    //给支付数据
    payData.value={
        orderId:res.data.data.orderId,
        subject:res.data.data.product_code,
        totalPrice:res.data.data.totalPrice/100
    }
})


import {payApi} from '@/api/api'
let payData=ref({
    orderId:'',
    subject:'',
    totalPrice:0
})

const onSubmit=()=>{
    payApi(payData.value).then((res)=>{
        window.open(res.data.data,'_blank')
    })
}
</script>

<style lang="scss" scoped>

</style>